package 每日温度;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;

//单调栈
public class Solution2 {
    public int[] dailyTemperatures(int[] T) {
        int len = T.length;
        Deque<Integer> stack = new LinkedList<>();
        int[] ans = new int[len];
        for(int i = 0; i < len;i++){
            int temperature = T[i];
            while(!stack.isEmpty()&& temperature > T[stack.peek()]){
                Integer pop = stack.pop();
                ans[pop] = i - pop;
            }
            stack.push(i);
        }
        return ans;
    }
}
